package com.qmds.deviceserver.type.service.impl;

import com.qmds.common.core.entity.ProductType;
import com.qmds.common.core.vo.R;
import com.qmds.deviceserver.type.dao.ProductTypeMapper;
import com.qmds.deviceserver.type.param.ProductTypeAddParam;
import com.qmds.deviceserver.type.service.ProductTypeService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * --- 代码敲烂 月薪过万 ---
 *
 * @author ShiJiaWei
 * @date 2024/9/9
 * @desc:
 */
@Service
public class ProductTypeServiceImpl implements ProductTypeService {
    @Resource
    private ProductTypeMapper productTypeMapper;

    @Override
    public R<List<ProductType>> findAll() {
        List<ProductType> productTypes = productTypeMapper.selectList(null);
        if (productTypes != null) {
            return R.ok(productTypes);
        }
        return R.fail();
    }

    @Override
    public R<Integer> addProductType(ProductTypeAddParam typeParam) {
        if (typeParam == null) {
            return R.fail("参数有误");
        }
        ProductType productType = new ProductType();
        BeanUtils.copyProperties(typeParam, productType);
        if(productTypeMapper.insert(productType) > 0) {
            return R.ok();
        }
        return R.fail();
    }
}
